<extend name="public:base"/>

<block name="left">
    <div class="mark_bar cl">
        <a href="javascript:history.back(-1);" class="goback fl"><i class="iconfont">&#xe600;</i></a>
        <p>登录</p>
        <a href="{:url('user/passport/register')}" class="btm">注册</a>
    </div>
</block>

<block name="main">
    <div class="container">

        <form action="{:url('user/passport/login')}" method="post" id="login">

            <div class="form">
                <div class="input_form">
                    <div class="input_form_bar">
                        <p class="fl">手机号码</p>
                        <input placeholder="请输入手机号码/用户名" name="phone" id="phone" value="{$phone|default=''}" size="11"
                               maxlength="11" type="text" autocomplete="off"/>
                        <div class="cl"></div>
                    </div>
                    <div class="input_form_bar">
                        <p class="fl">登录密码</p>
                        <input placeholder="请输入密码" name="password" maxlength="16" id="password" type="password" autocomplete="off"/>
                        <i class="iconfont passeye">&#xe626;</i>
                        <div class="cl"></div>
                    </div>
                    <!--<div class="input_form_bar hide" id="imgCode">
                        <p>图形验证码</p>
                        <input placeholder="图形验证码" name="verify" id="verify" disabled="disabled" class="input_t"
                               value="" size="4" maxlength="4" autocomplete="off" type="text"/>
                        <img src="" class="verifyimg">
                        <div class="cl"></div>
                    </div>-->
                </div>
            </div>
            <div class="wrap">
                <button type="submit" class="submit" id="loginsubmit">立即登录</button>
                <a href="{:url('user/passport/find')}" class="af60 small fr pt1">忘记密码？</a>
                <div class="cl"></div>
            </div>
        </form>
    </div>

</block>

<block name="menu"></block>

<block name="js">
    <script type="text/javascript" src="__JS__/check.js?v={:config('app_ver')}"></script>
    <script type="text/javascript">
        $(function () {

            $(".registerTab a").click(function () {
                $(this).addClass("on").siblings("a").removeClass("on");
                $("#isBorrow").val($(this).index() === 0 ? 0 : 1);
            });

            // 是否显示图形验证码
            function showImgCode() {
                $("#imgCode").show();
                $("#verify").removeAttr("disabled");
            }

            function hideImgCode() {
                $("#imgCode").hide();
                $("#verify").attr("disabled", "disabled");
            }

            function ajax_username() {
                var phone = $("#phone").val();
                var _reg = /^[0-9]*[1-9][0-9]*$/;
                if (phone.length === 0) return false
                if (phone.length === 11 && _reg.test(phone)) {
                    if (!checkPhone()) {
                        return false;
                    }
                }
                $.post("/uc/sign/ajax_username.html", {"phone": phone}, success, "json");
                return false;

                function success(data) {
                    if (data.code == 0) {
                        wjtips(data.msg);
                    } else if (data.code == 1) {
                        if (data.data <= 0) {
                            hideImgCode();
                        } else {
                            showImgCode();
                        }
                    }
                }
            }

            $("#phone").blur(function () {
                ajax_username();
            });

            var name = !getCookie("name") ? '' : getCookie("name") ,
                user_type = isNaN(getCookie("userType")) ? '' : getCookie("userType");
            if (name.length > 0) { $("#phone").val(name); }
            if(parseInt(user_type) === 1){
                $("#isBorrow").val(1);
                $(".registerTab a").eq(1).addClass("on").siblings().removeClass("on");
            }else{
                $("#isBorrow").val(0);
                $(".registerTab a").eq(0).addClass("on").siblings().removeClass("on");
            }

            $("#login").submit(function () {
                var isTrue = $("#verify").attr("disabled");
                var phone = $("#phone").val();
                if (phone.length == 11) {
                    if (!checkPhone()) {
                        return false;
                    }
                }
                if (!checkLoginPassword()) return false;
                if (!isTrue) {
                    if (!checkVerify()) return false;
                }
                return ajax_post2($(this), '', '', '', '登录中...');
            });

            var ajax_post2 = function (obj, parme, action, falseCallback, loadingtips) {
                loadingtips = loadingtips || '数据处理中...';
                layer.closeAll();
                layer.open({
                    type: 2,
                    content: loadingtips
                });
                setTimeout(function () {
                    if (parme && action) {
                        $.post(action, parme, success, "json");
                    }
                    else {
                        $.post(obj.attr("action"), obj.serialize(), success, "json");
                    }
                }, 1000);
                return false;

                function success(d) {
                    if (d.code == 1) {
                        $("#loginBtn").val("登录成功");
                        var user = $("#phone").val(),
                            bankTips = $("#bankCloseBox") ,
                            select_value = $("#isBorrow").val() ,
                            user_type = 0;
                        if(select_value == 1){ user_type = 1; }
                        $.cookie('login_error', null, {path: '/'});
                        $.cookie("name", user, {path: "/", expires: 3});
                        $.cookie("userType", user_type , {path: "/", expires: 3});
                        layer.closeAll();
                        if (d.data.deposit_status === 0 && d.data.audit_status !== 1 && is_bank === 1) {
                            bankTips.fadeIn("fast").find(".closeBtn").attr("data-href", d.data.redirect_url);
                            return false;
                        }
                        wjtips(d.msg);
                        var refer = d.url || d.data.redirect_url;
                        if (refer) {
                            setTimeout(function () { window.location.href = refer }, 1500);
                        } else {
                            setTimeout("location.reload()", 1500);
                        }
                    } else {
                        if(d.code == -10){
                            layer.closeAll();
                            layer.open({
                                content: d.msg
                                ,btn: ['确认', '取消']
                                ,yes: function(){
                                    layer.closeAll();
                                    var is_borrow = $("#isBorrow").val();
                                    var send_data = {phone : d.data.phone , password : d.data.password, is_borrow:is_borrow};
                                    $.post("{:url('uc/sign/regborrower')}", send_data, function (data) {
                                        wjtips(data.msg);
                                        if (data.code === 1) {
                                            setTimeout(function () {
                                                window.location.href = data.data;
                                            },2000);
                                        }else{
                                            setTimeout(function () {
                                                window.location.reload();
                                            },2000);
                                        }
                                        return false;
                                    }, "json");
                                    return false;
                                },no:function () {
                                    layer.closeAll();
                                }
                            });
                        }else{
                            layer.closeAll();
                            if(d.msg !== null){
                                wjtips(d.msg);
                            }else{
                                for (var i in d.data) {
                                    wjtips(d.data[i]);
                                }
                            }
                            if (d.code != -10) {
                                $("#imgCode").removeClass("hide").find(".input_t").removeAttr("disabled");
                            }
                            showImgCode();
                        }
                        return false;
                    }
                }
            };
        });
    </script>
</block>